<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var flag = true;
        var a = 0;
        for (i = 1; i <= 100; i++) {  
            var res = flag ? `${a += 1 / i}` : `${a -= 1 / i}`;
            flag = !flag;
            // console.log(flag)
            // var b = '我是' + a + 'add';
            // var b =`我是${a}add`;
            // console.log(b);
            // flag?'+':'-'
            // a (flag)=1/i
            // console.log(res);
        }
        console.log(a);
    </script>
</body>

</html>